package com.cloud.admin.controller;

import cn.hutool.extra.servlet.ServletUtil;
import com.cloud.admin.beans.qo.LoginRequest;
import com.cloud.common.base.Result;
import com.cloud.common.enums.ResultEnum;
import com.cloud.common.var.StaticVar;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 登录
 * @author Aijm
 * @since 2019/5/17
 */
@RestController
@RequestMapping("/")
@Slf4j
public class LoginController {

    @Value("${auth.clientId}")
    String clientId;
    @Value("${auth.clientSecret}")
    String clientSecret;
    @Value("${auth.cookieDomain}")
    String cookieDomain;
    @Value("${auth.cookieMaxAge}")
    int cookieMaxAge;

    @PostMapping("/userLogin")
    public Result<String> login(@RequestBody LoginRequest loginRequest) {
        if(loginRequest == null || StringUtils.isEmpty(loginRequest.getLoginName())){
            return Result.error(ResultEnum.LOGIN_NAME_NULL);
        }
        if(loginRequest == null || StringUtils.isEmpty(loginRequest.getPassword())){
            return Result.error(ResultEnum.LOGIN_PASSWORD_NULL);
        }
        String sessionId = RequestContextHolder.getRequestAttributes().getSessionId();
        //账号
        String loginName = loginRequest.getLoginName();
        // 密码
        String password = loginRequest.getPassword();
        //申请令牌
        //将令牌存储到redis中

        return Result.success("token");
    }


}
